package modelLayer;

import java.util.ArrayList;
import java.util.List;

public class SubjectCon {
	private static SubjectCon instance;
	private List<Subject> subjects;
	
	public SubjectCon(){
		subjects = new ArrayList<Subject>();
	}
	
	public static SubjectCon getInstance(){
		if (instance == null){
			instance = new SubjectCon();
		}
		return instance;
	}
	
	public boolean addSubject(Subject s){
		return subjects.add(s);
	}
	
	public boolean removeSubject(Subject s){
		boolean found = false;
		for (int i = 0; i < subjects.size() && !found; i ++){
			if (subjects.get(i).equals(s)){
				found = subjects.remove(subjects.get(i));
			}
		}
		return found;
	}
	
	public Subject findSubject(String name){
		boolean found = false;
		Subject s = null;
		for (int i = 0; i < subjects.size() && !found; i ++){
			if (subjects.get(i).getName().equalsIgnoreCase(name)){
				s = subjects.get(i);
				found = true;
			}
		}
		return s;
	}

	/**
	 * @return the subjects
	 */
	public List<Subject> getSubjects() {
		return subjects;
	}

	/**
	 * @param subjects the subjects to set
	 */
	public void setSubjects(List<Subject> subjects) {
		this.subjects = subjects;
	}
	
	

}
